﻿Imports Microsoft.VisualBasic
Imports System.Web.HttpContext

Public Class clsUser
    Public UserID As String
    Public UOrganizationID As String
    Public OrganizationID As String
    Public UserType As My.UserType
    Public RegionID As String
    Public RegionType As My.RegionType
    Public AdminOrganizationID As String '科室 ID
    Public IsSSOAccount As Boolean

    Public UserName As String
    Public OrganizationName As String

    Public Sub New()
        Dim user As clsUser = Me
        Dim UserID As String = Current.Session("UserID")
        user.UserID = clsAuth.GetUserID()

      
        user.UserType = New My.UserType(clsCookie.CookieGet("UserTypeValue"))
        user.UOrganizationID = clsCookie.CookieGet("UOrganizationID")
        user.OrganizationID = clsCookie.CookieGet("OrganizationID")

        'user.RegionID = HttpContext.Current.Request.Cookies("RegionID").Value
        'user.RegionType = New My.RegionType(HttpContext.Current.Request.Cookies("RegionType").Value)
      
        user.UserName = HttpUtility.UrlDecode(clsCookie.CookieGet("UserName"))
        user.OrganizationName = HttpUtility.UrlDecode(clsCookie.CookieGet("OrganizationName"))

        'user.IsSSOAccount = IIf(HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies("IsSSOAccount").Value) = "Y", True, False)
    End Sub

    Public Function GetForumLoginID() As Nullable(Of Integer)
        Dim dat As New clsData("yafnet")
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select UserID from yaf_UserView where EmployeeID = @EmployeeID ")
        sql.AddWithValue("EmployeeID", Me.UserID)

        Dim dt As Data.DataTable = dat.GetData(sql)

        If dt.Rows.Count > 0 Then
            Return dat.GetData(sql).Rows(0)("UserID")
        Else
            Return Nothing
        End If

    End Function

    Public Shared Function GetUserAddress(ByVal userID As String) As String
        Dim sql As New MyStringBuilder
        Dim dat As New clsData
        Dim dt As Data.DataTable

        Dim emailColumnName As String

        'If MyObj.IsProductionEnvironment() = True Then
        emailColumnName = "Email"
        'Else
        'emailColumnName = "TestEmail"
        'End If

        sql.AppendFormat("select {1} from [Employee] where EmployeeID = '{0}' ", userID, emailColumnName)

        dt = dat.GetData(sql)
        If dt.Rows.Count > 0 Then
            Return dat.GetData(sql).Rows(0)(0)
        Else
            Return userID
        End If

    End Function

    'Public Shared Function GetCurrentUser(ByVal userID As String) As clsUser

    '    Return user
    'End Function

End Class
